
# a = 'asdfghjkl'
# b = 'sfhjl'
# mylist = [ a[a.index(x):(a.index(x)+1)] for x in list(b)]
# print(''.join(mylist))

#https://oapi.dingtalk.com/connect/qrconnect?appid=dingoaukgkwqknzjvamdqh&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=http://localhost:8000/dingding_back/


#curl 'https://oapi.dingtalk.com/sns/getuserinfo_bycode?signature=I7QZp0pUefHVK8cv2159ywFQMpdZRCfFIi8UbDQiRNI%3D&timestamp=1576903122294&accessKey=dingoaukgkwqknzjvamdqh' -H "Content-Type:application/json" -X POST --data '{"tmp_auth_code":"bb367f9a0c3e31698bb92434246a392e"}'


import requests
import time
import hmac
import base64
from hashlib import sha256
import urllib
import json
t = time.time()



timestamp = str((int(round(t * 1000))))
#print(timestamp)
#timestamp = '1546084445901'
#print(timestamp)
appSecret ='ly-AzMKMmCKQP3geaILT_An32kEfKO3HeOtApy5CgKwjytevVZC0WYsT2gxMB160'





signature = base64.b64encode(hmac.new(appSecret.encode('utf-8'),timestamp.encode('utf-8'), digestmod=sha256).digest())

print(urllib.parse.quote(signature.decode("utf-8")))
print('HCbG3xNE3vzhO%2Bu7qCUL1jS5hsu2n5r2cFhnTrtyDAE%3D')

payload = {'tmp_auth_code':'329c6cf85eb038c49a580e4843a525a2'}
headers = {'Content-Type': 'application/json'}
res = requests.post('https://oapi.dingtalk.com/sns/getuserinfo_bycode?signature='+urllib.parse.quote(signature.decode("utf-8"))+"&timestamp="+timestamp+"&accessKey=dingoaukgkwqknzjvamdqh",data=json.dumps(payload),headers=headers)

res = json.loads(res.text)
print(res)